package com.sslite.util;

import java.io.FileInputStream;
import java.util.Properties;

public enum SSLiteProperties {
	CNBC_URL("cnbc.url"),
	CNBC_URL_EXTN( "cnbc.url.extension" ),
	CNBC_URL_EXTN_COMPANY_PROFILE("cnbc.url.extension.company.profile"),
	GOOGLE_STOCK_SCREENER_URL( "google.stock.screener.url" ),
	METADATA_CSV_FILE_PATH ( "metadata.csv.file.path" ),
	SYMBOLS ( "symbols" ),
	GENERATE_REPORT_ONLY( "generate.report.only" ),
	CACHE_FOLDER("cache.folder"),
	GOOGLE_URL_INTRA_DAY("google.url.intra.day"),
	ONE_MINUTE_DATA_FOLDER("one.minute.data.folder"),
	SLEEP_TIME_MILLIS("sleep.time.millis"),
	RPT_PATH_DAILYVOLUMEAGGREGATE("rpt.path.dailyvolumeaggregate"),
	RPT_PATH_DAILYVOLUMEAGGREGATE_QUALIFIED("rpt.path.dailyvolumeaggregate.qualified"),
	RPT_PATH_EFFECTSOFHIGHVOLUME("rpt.path.effectsofhighvolume"),
	RPT_PATH_EFFECTSOFHIGHVOLUME_QUALIFIED("rpt.path.effectsofhighvolume.qualified"),
	RPT_INTRA_DAY_SNAPSHOT_FOLDER("rpt.intra.day.snapshot.folder"),
	QUALIFICATION_MAX_VXC_GREATER_THAN("qualification.max.vxc.greater.than"),
	QUALIFICATION_MAX_VOL_TIMES_OF_AVERAGE_VOL("qualification.max.vol.times.of.average.vol"),
	TMP_RPT_FOLDER_DAILYVOLUMEAGGREGATE("tmp.rpt.folder.dailyvolumeaggregate"),
	TMP_RPT_FOLDER_EFFECTSOFHIGHVOLUME("tmp.rpt.folder.effectsofhighvolume"),
	EFFECTSOFHIGHVOLUME_JOSQL_QUERY("effectsofhighvolume.josql.query"),
	RPT_THREAD_POOL("rpt.thread.pool"),
	LOST_REPORT_DATA_FILE_TO_BE_DELETED_AFTER_AUG_2014("lost.report.data.file.to.be.deleted.after.aug.2014"),
	RPT_DAILYVOLUMEAGGREGATE_GENERATE("rpt.dailyvolumeaggregate.generate"),
	RPT_EFFECTSOFHIGHVOLUME_GENERATE("rpt.effectsofhighvolume.generate");
	
	private final String property;
	private SSLiteProperties(String property){
		this.property = property;
	}
	
	/** Order of lookup: 
	 *  1) System Properties, 
	 *  2) sslite.properties
	 *  
	 * @return the first non-null property value.
	 */
	public String getValue(){
		String value = System.getProperty( this.property );
		if( value == null ){
			value = properties.getProperty( this.property );
		}
		return value;
	}
	
	private final static Properties properties = new Properties();
	static{
		FileInputStream fis = null;
		String propsFilePath = System.getProperty("propsFilePath");
		try{
			fis = new FileInputStream( propsFilePath );
			properties.load( fis );
		}
		catch(Exception e){
			System.out.println("SSLiteProperties: Exception in loading properties from " +propsFilePath+ " -> " +e.getMessage());
			e.printStackTrace();
		}
		finally{
			if( fis != null ){
				try{
					fis.close();
				}
				catch(Exception e){
					e.printStackTrace();
					throw new RuntimeException("Exception in closing properties file at " +propsFilePath+ " --> " +e);
				}
			}
		}
	}
}
